package online.foxnull2.foxmall.gateway.config;

import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
import com.alibaba.fastjson.JSON;
import online.foxnull2.common.exception.BizCodeEnum;
import online.foxnull2.common.utils.R;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

//@Configuration
public class SentinelGatewayConfig {

    //    @PostConstruct
    public void init() {
        GatewayCallbackManager.setBlockHandler((exchange, t) -> {
            R r = R.error(BizCodeEnum.TOO_MANY_REQUEST.getCode(), BizCodeEnum.TOO_MANY_REQUEST.getMsg());
            String text = JSON.toJSONString(r);
            return ServerResponse.ok().body(Mono.just(text), String.class);
        });
    }
}
